package com.zhongxi.guoyuan.adapter.beautifulStore;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.service.ServiceItemData;
import com.zhongxi.guoyuan.url.Url;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Administrator on 2016/10/29.
 */

public class ProjectAdapter extends BaseAdapter {
    private List<ServiceItemData> data;
    private LayoutInflater mLayoutInflater;
    private Context context;

    public ProjectAdapter(Context context, List<ServiceItemData> data) {
        this.mLayoutInflater = LayoutInflater.from(context);
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.adapter_meirong, parent, false);
            holder.ivImg = (ImageView) convertView.findViewById(R.id.ivImg);
            holder.tvText = (TextView) convertView.findViewById(R.id.tvText);
           // holder.tvTruePrice = (TextView) convertView.findViewById(R.id.tvTruePrice);
            holder.tvOriginPrice = (TextView) convertView.findViewById(R.id.tvOriginPrice);
            holder.tvRewardCoin = (TextView) convertView.findViewById(R.id.tvRewardCoin);
            holder.tvView = (TextView) convertView.findViewById(R.id.tvView);
            holder.tvCash = (TextView) convertView.findViewById(R.id.tvCash);
            holder.ivLimit = (ImageView) convertView.findViewById(R.id.ivLimit);
            holder.tvTime = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        try {
            ServiceItemData list = data.get(position);
            if(null!=list.getThumbnail()&&!"".equals(list.getThumbnail())){
                Glide.with(context).load(Url.IMG_URL+list.getThumbnail()).placeholder(R.mipmap.iv_loading).fitCenter().into(holder.ivImg);
            }
            if(null != list.getName()&&!"".equals(list.getName())){
                holder.tvText.setText(list.getName());
            }else{
                holder.tvText.setText("");
            }
            if(null!=list.getPrice()&&!"".equals(list.getPrice())){
                holder.tvCash.setText(list.getPrice()+"元");
                holder.tvRewardCoin.setText("[权益会员返"+new BigDecimal(list.getPrice()).multiply(new BigDecimal(list.getBacksilverratio())).intValue()/100+"银币]");
            }else{
                holder.tvCash.setText("");
            }
//            if(null!=list.getInnerprice()&&!"".equals(list.getInnerprice())){  //去掉美币
//                holder.tvTruePrice.setText(list.getInnerprice());
//            }else{
//                holder.tvTruePrice.setText("");
//            }
            if("0".equals(list.getIslimited())){
                holder.ivLimit.setVisibility(View.GONE);
            }else{
                holder.ivLimit.setVisibility(View.VISIBLE);
            }
            if(null!=list.getMarketprice()&&!"".equals(list.getMarketprice())){
                holder.tvOriginPrice.setText("原价：" + list.getMarketprice());
                holder.tvOriginPrice.setPaintFlags(Paint. STRIKE_THRU_TEXT_FLAG);
            }else{
                holder.tvOriginPrice.setText("");
            }
            if(null!=list.getViewnum()&&!"".equals(list.getViewnum())){
                holder.tvView.setText(list.getViewnum());
            }else{
                holder.tvView.setText("");
            }
            if(null!=list.getServicetime()&&!"".equals(list.getServicetime())){
                holder.tvTime.setText(list.getServicetime()+"分钟");
            }else{
                holder.tvTime.setText("");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        return convertView;
    }

    class ViewHolder{
        private ImageView ivImg;
        private TextView tvText;
      //  private TextView tvTruePrice;
        private TextView tvOriginPrice;
        private TextView tvRewardCoin;
        private TextView tvView;
        private TextView tvCash;
        private ImageView ivLimit;
        private TextView tvTime;
    }
}
